package com.woniuxy.aop.service.impl;

import com.woniuxy.aop.bean.Menu;
import com.woniuxy.aop.mapper.MenuMapper;
import com.woniuxy.aop.service.IMenuService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author linke
 * @version 1.0
 * @className: MenuServiceImpl
 * @description: 菜单服务实现类
 * @date 2021/11/13 11:18
 * @Service注解 将IMenuService接口的实例交给spring容器管理
 * @Transactional 只读事务声明，用于对查询事务的优化
 */
@Transactional(readOnly = true)
@Service
public class MenuServiceImpl implements IMenuService {
    /**
     * 注入持久层对象
     */
    @Resource
    private MenuMapper menuMapper;

    @Override
    public List<Menu> findAll() {
        return menuMapper.findAll();
    }

    //REPEATABLE_READ可重复读取级别    在执行修改操作提交后，只允许查询
    @Transactional(isolation = Isolation.REPEATABLE_READ,rollbackFor = Exception.class)
    @Override
    public void saveMenu(Menu menu) {
        menuMapper.saveMenu(menu);

    }
    //REPEATABLE_READ可重复读取级别    在执行修改操作提交后，只允许查询
    @Transactional(isolation = Isolation.REPEATABLE_READ,rollbackFor = Exception.class)
    @Override
    public void updateMenu(Menu menu) {
        menuMapper.updateMenu(menu);
    }

    @Override
    public Menu getOneById(Integer id) {
        return menuMapper.getOneById(id);
    }

    //REPEATABLE_READ可重复读取级别    在执行修改操作提交后，只允许查询
    @Transactional(isolation = Isolation.REPEATABLE_READ,rollbackFor = Exception.class)
    @Override
    public void deleteMenu(Integer id) {
        menuMapper.deleteMenu(id);
    }
}
